package com.hzhr.iot.device.convertor;

import com.hzhr.iot.device.convertor.custom.*;
import com.hzhr.iot.core.util.HzhrTypeUtil;
import com.hzhr.iot.core.util.HzhrJsonUtil;
import java.util.Map;
import com.hzhr.iot.device.model.implFactory.ImplFactoryModel;
import com.hzhr.iot.device.entity.ImplFactoryEntity;
import com.hzhr.iot.device.entity.ext.ImplFactoryEntityExt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.hzhr.iot.device.model.implFactory.ImplFactoryModel;
import com.hzhr.iot.device.model.implFactory.ImplFactoryGetModel;
import com.hzhr.iot.device.queryModel.custom.ImplFactoryCustomQueryModel;

@Component
public class ImplFactoryConvertor {
    @Autowired
    AlarmDataCustomConvertor alarmDataCustomConvertor;
    @Autowired
    CollectDataCustomConvertor collectDataCustomConvertor;
    @Autowired
    CollectDeviceCustomConvertor collectDeviceCustomConvertor;
    @Autowired
    CollectDeviceTypeCustomConvertor collectDeviceTypeCustomConvertor;
    @Autowired
    DeviceInfoCardCustomConvertor deviceInfoCardCustomConvertor;
    @Autowired
    DeviceMaintenanceCardCustomConvertor deviceMaintenanceCardCustomConvertor;
    @Autowired
    DeviceMaintenanceCardItemCustomConvertor deviceMaintenanceCardItemCustomConvertor;
    @Autowired
    ImplIotDeviceTypeCustomConvertor implIotDeviceTypeCustomConvertor;
    @Autowired
    ImplRecordCustomConvertor implRecordCustomConvertor;
    @Autowired
    IotDeviceCustomConvertor iotDeviceCustomConvertor;
    @Autowired
    IotDeviceTypeCustomConvertor iotDeviceTypeCustomConvertor;
    @Autowired
    OptionsCustomConvertor optionsCustomConvertor;
    @Autowired
    ProdFactoryCustomConvertor prodFactoryCustomConvertor;
    @Autowired
    RegulatorCollectDataCustomConvertor regulatorCollectDataCustomConvertor;
    @Autowired
    UserCompanyCustomConvertor userCompanyCustomConvertor;

    public ImplFactoryEntity implFactoryModel2entity(ImplFactoryModel in) {
        //未转换字段: 
        if (in == null) return null;
        ImplFactoryEntity result = new ImplFactoryEntity();

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setDes(HzhrTypeUtil.string2string(in.getDes()));
        result.setType(HzhrTypeUtil.integer2integer(in.getType()));
        return result;
    }
    public ImplFactoryEntity implFactoryModel2entity(ImplFactoryModel in, ImplFactoryEntity ori) {
        //未转换字段: 
        if (in == null) return null;
        ImplFactoryEntity result = ori;

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setDes(HzhrTypeUtil.string2string(in.getDes()));
        result.setType(HzhrTypeUtil.integer2integer(in.getType()));
        return result;
    }
    public List<ImplFactoryEntity> implFactoryModelList2entityList(List<ImplFactoryModel> in) {
        if (in == null) return null;
        List<ImplFactoryEntity> result = new ArrayList<>();
        for (ImplFactoryModel item : in) {
            result.add(implFactoryModel2entity(item));
        }
        return result;
    }
    public ImplFactoryModel entity2implFactoryModel(ImplFactoryEntity in) {
        //未转换字段: 
        if (in == null) return null;
        ImplFactoryModel result = new ImplFactoryModel();

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setDes(HzhrTypeUtil.string2string(in.getDes()));
        result.setType(HzhrTypeUtil.integer2integer(in.getType()));
        return result;
    }
    public List<ImplFactoryModel> entityList2implFactoryModelList(List<ImplFactoryEntity> in) {
        if (in == null) return null;
        List<ImplFactoryModel> result = new ArrayList<>();
        for (ImplFactoryEntity item : in) {
            result.add(entity2implFactoryModel(item));
        }
        return result;
    }
    public ImplFactoryModel ext2implFactoryModel(ImplFactoryEntityExt in) {
        //未转换字段: 
        if (in == null) return null;
        ImplFactoryModel result = new ImplFactoryModel();

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setDes(HzhrTypeUtil.string2string(in.getDes()));
        result.setType(HzhrTypeUtil.integer2integer(in.getType()));
        return result;
    }
    public List<ImplFactoryModel> extList2implFactoryModelList(List<ImplFactoryEntityExt> in) {
        if (in == null) return null;
        List<ImplFactoryModel> result = new ArrayList<>();
        for (ImplFactoryEntityExt item : in) {
            result.add(ext2implFactoryModel(item));
        }
        return result;
    }
    public ImplFactoryGetModel extList2implFactoryGetModel(List<ImplFactoryEntityExt> extList, Integer total, Integer changeCount, Map<String, Object> query) {
        List<ImplFactoryModel> modelList = extList2implFactoryModelList(extList);
        if (modelList == null) {
            ImplFactoryGetModel result = new ImplFactoryGetModel();
            result.setTotal(total);
            result.setChangeCount(changeCount);
            return result;
        }

         String _show = HzhrTypeUtil.object2string(query.get("_show"));
         Boolean _show_info = query.get("_show_info") != null ? Boolean.parseBoolean(query.get("_show_info").toString()) : false;

        if (!_show_info) {
            for (ImplFactoryModel model : modelList) {
                model.setDes(null);
                model.setType(null);
            }
        }

        ImplFactoryGetModel result = new ImplFactoryGetModel();
        if ("one".equals(_show)) {
            if (modelList.size() > 0) {
                result.setModel(modelList.get(0));
            }
         }
        if ("list".equals(_show)) {
            result.setModelList(modelList);
        }
        result.setTotal(total);
        result.setChangeCount(changeCount);
        return result;
    }
    public ImplFactoryGetModel entity2implFactoryGetModel(ImplFactoryEntity entity, Integer total, Integer changeCount, Map<String, Object> query) {
        List<ImplFactoryEntityExt> extList = new ArrayList<>();
        if (entity == null) return extList2implFactoryGetModel(extList, total, changeCount, query);
        extList.add(HzhrJsonUtil.convertObjectType(entity, ImplFactoryEntityExt.class));
        return extList2implFactoryGetModel(extList, total, changeCount, query);
     }
    public ImplFactoryCustomQueryModel implFactoryService_query2queryModel(Map<String, Object> query) {
        ImplFactoryCustomQueryModel queryModel = new ImplFactoryCustomQueryModel();

        Integer _equal_type = HzhrTypeUtil.object2integer(query.get("_equal_type"));
        if (_equal_type != null) {
            queryModel.setEqual_type(_equal_type);
         }

        Boolean _show_info = HzhrTypeUtil.object2boolean(query.get("_show_info"));
        if (_show_info != null && _show_info) {
            queryModel.setShow(true);
            queryModel.setShow(true);
        }

        Integer page = HzhrTypeUtil.object2integer(query.get("_page"));
        Integer count = HzhrTypeUtil.object2integer(query.get("_count"));
        queryModel.setPage(page, count);

        return queryModel;
    }

}

